package com.ctsi.ssdc.controller;

import com.ctsi.ssdc.entity.EconomicIndicators;
import com.ctsi.ssdc.service.EconomicIndicatorsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.data.web.PageableDefault;

/**
 * 用户信息表日期(EconomicIndicators)表控制层
 *
 * @author makejava
 * @since 2023-03-11 21:00:46
 */
@RestController
@RequestMapping("excel/01")
public class EconomicIndicatorsController {
    /**
     * 服务对象
     */
    @Resource
    private EconomicIndicatorsService economicIndicatorsService;

    /**
     * 分页查询
     *
     * @param economicIndicators 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<EconomicIndicators>> queryByPage(EconomicIndicators economicIndicators,@PageableDefault(page = 0, size = 50) Pageable pageRequest) {
        return ResponseEntity.ok(this.economicIndicatorsService.queryByPage(economicIndicators,(PageRequest) pageRequest));
    }

    /**
     * 分页查询(按excel排序)
     *
     * @param economicIndicators 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping("order")
    public ResponseEntity<Page<EconomicIndicators>> queryByPageOrder(EconomicIndicators economicIndicators,@PageableDefault(page = 0, size = 50) Pageable pageRequest) {
        return ResponseEntity.ok(this.economicIndicatorsService.queryByPageOrder(economicIndicators,(PageRequest) pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<EconomicIndicators> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.economicIndicatorsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param economicIndicators 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<EconomicIndicators> add(EconomicIndicators economicIndicators) {
        return ResponseEntity.ok(this.economicIndicatorsService.insert(economicIndicators));
    }

    /**
     * 编辑数据
     *
     * @param economicIndicators 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<EconomicIndicators> edit(EconomicIndicators economicIndicators) {
        return ResponseEntity.ok(this.economicIndicatorsService.update(economicIndicators));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.economicIndicatorsService.deleteById(id));
    }

}

